<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.ProjectDAO"%>
<%@page import="db.SupplierDAO"%>
<%@page import="db.MaterialDAO"%>
<%@page import="org.json.JSONObject"%>
<%@page import="db.ReccompanyDAO"%>
<%@page import="db.CompanyDAO"%>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	ProjectDAO projectDao = (ProjectDAO)ctx.getBean("ProjectDAO");
	SupplierDAO supplierDao = (SupplierDAO)ctx.getBean("SupplierDAO");
	MaterialDAO materialDao = (MaterialDAO)ctx.getBean("MaterialDAO");
	ReccompanyDAO reccompanyDao = (ReccompanyDAO)ctx.getBean("ReccompanyDAO");
	CompanyDAO companyDao = (CompanyDAO)ctx.getBean("CompanyDAO");
	
	JSONObject json = new JSONObject();
	
	String proKeyword = request.getParameter("proKeyword");
	String proCode = request.getParameter("proCode");
	String supKeyword = request.getParameter("supKeyword");
	String matKeyword = request.getParameter("matKeyword");
	String matCode = request.getParameter("matCode");
	String recKeyword = request.getParameter("recKeyword");
	String comKeyword = request.getParameter("comKeyword");
	
	int tid = (Integer)session.getAttribute("tid");
	
	if(proKeyword != null){
		Map map = projectDao.getProject(0,0,
				new String[][]{new String[]{"desc","date"}},
				new Object[][]{new Object[]{"like","code",proKeyword},new Object[]{"eq","isDelete",0}},
				new String[][]{new String[]{"group","code"}},
				null
				);
		json.put("map",map);
		out.print(json.toString());
	}
	
	if(proCode != null){
		Map map = projectDao.getProject(0,0,
				new String[][]{new String[]{"desc","date"}},
				new Object[][]{new Object[]{"eq","code",proCode},new Object[]{"eq","isDelete",0}},
				new String[][]{new String[]{"","id"}, new String[]{"","name"}},
				null
				);
		json.put("map",map);
		out.print(json.toString());
	}
	
	if(supKeyword != null){
		Map map = supplierDao.getSupplier(0,0,
				new String[][]{new String[]{"desc","date"}},
				new Object[][]{new Object[]{"like","name",supKeyword},new Object[]{"eq","isDelete",0},new Object[]{"eq","teamId",tid}},
				new String[][]{new String[]{"","id"}, new String[]{"","name"}},
				null
				);
		json.put("map",map);
		out.print(json.toString());
	}
	
	if(matKeyword != null){
		Map map = materialDao.getMaterial(0,0,
				new String[][]{new String[]{"desc","date"}},
				new Object[][]{new Object[]{"like","code",matKeyword},new Object[]{"eq","isDelete",0},new Object[]{"eq","teamId",tid}},
				new String[][]{new String[]{"group","code"}},
				null
				);
		json.put("map",map);
		out.print(json.toString());
	}
	
	if(matCode != null){
		Map map = materialDao.getMaterial(0,0,
				new String[][]{new String[]{"desc","date"}},
				new Object[][]{new Object[]{"eq","code",matCode},new Object[]{"eq","isDelete",0},new Object[]{"eq","teamId",tid}},
				new String[][]{new String[]{"","id"},new String[]{"","name"}, new String[]{"","company"}},
				null
				);
		json.put("map",map);
		out.print(json.toString());
	}
	
	if(recKeyword != null){
		Map map = reccompanyDao.getReccompany(0,0,
				new String[][]{new String[]{"desc","id"}},
				new Object[][]{new Object[]{"like","name",recKeyword}},
				new String[][]{new String[]{"","id"},new String[]{"","name"}},
				null
				);
		json.put("map",map);
		out.print(json.toString());
	}
	
	if(comKeyword != null){
		Map map = companyDao.getCompany(0,0,
				new String[][]{new String[]{"desc","date"}},
				new Object[][]{new Object[]{"like","name",comKeyword},new Object[]{"eq","isDelete",0},new Object[]{"eq","teamId",tid}},
				new String[][]{new String[]{"","id"},new String[]{"","name"}},
				null
				);
		json.put("map",map);
		out.print(json.toString());
	}
%>